package com.jhj.springboot_exp3.controller;

import com.jhj.springboot_exp3.model.CsvModel;
import com.jhj.springboot_exp3.service.CsvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Controller
public class CsvController {

    @Autowired
    private CsvService csvService;

//    @ResponseBody
//    @RequestMapping("/")
//    public String Hello(){
//        return "hello";
//    }

    @RequestMapping("/hello")
    public String hello() {
        return "index";
    }
//    @RequestMapping("/search")
//    public ModelAndView index(@RequestParam(name = "key", required = false) String key){
//        Stream<CsvModel> dataModelStream = csvService.getCsvList().parallelStream();
//        List<CsvModel> dataModelList= null;
//
//        if (key == null){
//            dataModelList=dataModelStream.sorted((data1, data2) -> -Integer.compare(data1.getLatestTotalCases(), data2.getLatestTotalCases()))
//                    .collect(Collectors.toList());
//        }else{
//            dataModelList=dataModelStream.filter(data -> data.getState().startsWith(key) || data.getCountry().startsWith(key))
//                    .sorted((data1, data2) -> -Integer.compare(data1.getLatestTotalCases(), data2.getLatestTotalCases()))
//                    .collect(Collectors.toList());
//        }
//        System.out.println(dataModelList);
//        return new ModelAndView("index.html","DataList",dataModelList);
//    }
}
